<div id="result">
<?php echo $this->Session->flash(); ?>
  <div class="div_header1">Images for <?php echo $this->data['Category']['Category']['category_name']; ?></div>
	<form method="post" id="global_brand"  name="global_brand" action="<?php echo Configure::read('base_url')."add_category/addimagetitle/".$this->data['Category']['Category']['id'];?>">
	<br style="clear:both;">
    <table width="100%" cellspacing="0">
	<?php $i=0;foreach($this->data['Imagetitle'] as $image):
		$class = null;
		if ($i++ % 2 == 0)
		$class = ' class="alt"';
		
		?> 
      <tr>
        <td width="88" <?php echo $class;?>>Image <?php echo $i;?>:</td>
        <td width="92" <?php echo $class;?>><span id="inputbox_<?php echo $image['Imagetitle']['id'];?>"><?php echo $image['Imagetitle']['image_title'];?></span></td>
        <td width="90" <?php echo $class;?>><span id="savebutton_<?php echo $image['Imagetitle']['id'];?>">
		<a href="javascript:void(0);" class="clickToEdit" title="Click here to edit <?php echo $image['Imagetitle']['image_title'];?>" entryID="<?php echo $image['Imagetitle']['id'];?>">Edit</a>
		 |		
		<a href="javascript:void(0);" onclick="return showPop(this);" controller="add_category" action="deleteimagetitle" title="Delete" ElmID="<?php echo $image['Imagetitle']['id'];?>" ElmID2="<?php echo $this->data['Category']['Category']['id'];?>">Delete</a>
		</span>
		<span id="showsave_<?php echo $image['Imagetitle']['id'];?>"></span>
		</td>
      </tr>
	  <?php endforeach;?>
    </table> 
    
		
			<table width="100%" id="add_global_form" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="alt" width="144">					
					<input type="hidden" name="data[category_id]" value="<?php echo $this->data['Category']['Category']['id']; ?>">
					<?php echo $this->Form->input('image_title',array('label'=>false,'size'=>30,'id'=>'image_title','class'=>"required", 'title'=>"Enter Image title here")); ?>
				</td>
                <td width="347" class="alt"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="Save" id="Save" value="Add" /></td>
              </tr>
            </table>
       
       
     

  <div class="div_bottom1"></div>
</form>
</div>
<?php  echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js","jquery.pagination.js","jquery.tablesorter.min.js","jquery.tablednd.js")); ?>	 
 <script type="text/javascript">  
 jQuery(document).ready(function(){
 jQuery("#category_table").tablesorter({headers: { 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}}); 
 

		
		var v = jQuery("#global_brand").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
		var v2 = jQuery("#brandsettings").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
		
			
	$("form#global_brand a.clickToEdit").click(function()				
		{
			if($(this).attr('class')=='clickToEdit'){
				var entryID=($(this).attr("entryID"));			
				var inputValue=$("#inputbox_"+entryID).html();	
				
				var inputbox='<input type="hidden" value="'+entryID+'" name="data[id]"><input type="text" id="editbox_'+entryID+'" value="'+inputValue+'" name="data[brand_description]"><input type="hidden" value="'+inputValue+'" name="old_description" />';
				$("#inputbox_"+entryID).html(inputbox);
				
				var savebutton='<a href="javascript:void(0);" entryID="'+entryID+'" title="Save" onclick="return saveEntry(this);">Save</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);" entryID="'+entryID+'" onclick="cancelForm(this)">Cancel</a>';
				$("span#savebutton_"+entryID).hide().fadeOut("slow");		
				$("span#showsave_"+entryID).live("click", cancelForm).html(savebutton);	
								
				$('.required').attr('disabled',true);
				$('#Save').attr('disabled',true);
				
				$("form#global_brand a.clickToEdit").each(function (index,domEle) {
					  $(domEle).removeClass("clickToEdit"); 
					  $(domEle).addClass("clickToCancel"); 
				  });
			}
			else{
				return false;
			}			
			
		});
		
	});
	
	//Global brands/Styles/Conditions edit functions
	function saveEntry(param){		
		entryID=($(param).attr("entryID"));
		boxID="editbox_"+entryID;
		data = $("#global_brand").serialize();
		inputValue=$('input[id="'+boxID+'"]').val();
		$('input[name="old_description"]').val(inputValue);	
		$.ajax({
			type: 'POST',
			url: baseurl+"global_brand/edit/",
			data: data,
			dataType: 'json',
			success: function(data){
				if(data.message=="No")
				return false;
			}			
		});
		
		cancelForm(param);	
		return false;		
	}	
	
	function cancelForm(param){		
		var entryID=($(param).attr("entryID"));
		var boxID="editbox_"+entryID;
		var inputValue=$('input[name="old_description"]').val();	
		$("#inputbox_"+entryID).html(inputValue);
		$("span#savebutton_"+entryID).show().fadeIn("slow");		
		$("span#savebutton_"+entryID+" a").attr("class","clickToEdit");		
		$("span#showsave_"+entryID).die("click", cancelForm).text("");
		
		$("form#global_brand a.clickToCancel").each(function (index,domEle) {
					  $(domEle).removeClass("clickToCancel"); 
					  $(domEle).addClass("clickToEdit");
				  });
				  
		$('.required').removeAttr('disabled');
		$('#Save').removeAttr('disabled');
	}
 </script>